#include "bflb_flash.h"
#include "lcd.h"
#include "hzk.h"

uint32_t FLASH_ADDR_BASE=0x378000;
uint8_t MatrixBuff[32];

void getMatrix(const unsigned short nmCode)
{

	uint32_t offset;
	unsigned char GBH,GBL;
	unsigned short nm=nmCode;

	GBH=nm>>8;
	GBL=nm;
	if(GBH>=0xb0)
	{
		offset=((GBH-0xa7)*94+GBL-0xa1)*32;
	}else
	{
		offset=((GBH-0xa1)*94+GBL-0xa1)*32;
	}

    bflb_flash_read(FLASH_ADDR_BASE+offset, MatrixBuff, sizeof(MatrixBuff));

}


void GUI_Write16CnCharMatrix(unsigned char x, unsigned char y, uint8_t *cn, unsigned short wordColor, unsigned short backColor)
{
    uint8_t i=0, j;
	uint16_t zm;
    uint16_t color;
    while (*cn != '\0')
    {
        //setXY(x, y, x+15, y+15);
						zm=*cn;
						zm<<=8;
						zm|=*(cn+1);

						getMatrix(zm);


                for(i=0; i<32; i++)
                {   //MSK的位数
                    color=MatrixBuff[i];
                    for(j=0;j<8;j++)
                    {
                        if((color&0x80)==0x80)
                        {
                            //lcd_write_data_word(wordColor);
                            if(i%2==0) lcd_draw_point(x+j,y+i/2,wordColor);
                            else lcd_draw_point(x+j+8,y+i/2,wordColor);
                        }
                        else
                        {
                            //lcd_write_data_word(backColor);
                            if(i%2==0) lcd_draw_point(x+j,y+i/2,backColor);
                            else lcd_draw_point(x+j+8,y+i/2,backColor);
                        }
                        color<<=1;
                    }//for(j=0;j<8;j++)结束
                }


        cn += 2;
        x += 16;
    }
}
